<?php
	//echo $this->userType;
	$para=$_GET;

// 充值编号限制
if($para['rechargeId'] && $para['rechargeId']!="充值编号"){
	$para['rechargeId']=wjStrFilter($para['rechargeId'],0,0);
	if(!ctype_digit($para['rechargeId'])) throw new Exception('充值编号包含非法字符');
	$rechargeIdWhere="and c.rechargeId={$para['rechargeId']}";
}




// 用户名限制
if($para['username'] && $para['username']!='用户名'){
	$para['username']=wjStrFilter($para['username']);
	if(!ctype_alnum($para['username'])) throw new Exception('用户名包含非法字符,请重新输入');
	$whereStr .= " and u.username like '%{$para['username']}%' and (u.parentId={$this->user['uid']} or u.zparentId={$this->user['uid']} or u.gudongId={$this->user['uid']} ) ";
}

		switch($para['utype']){
			case 1:
				//我自己
				$whereStr .= " and c.uid={$this->user['uid']} ";
				break;
			case 2:
				//直属下线
				if($this->user['type']==1){
				$whereStr.=" and u.parentId={$this->user['uid']} and u.type=0 ";
				}elseif($this->user['type']==2){
				$whereStr.=" and u.zparentId={$this->user['uid']} and u.type=1 or (u.zparentId={$this->user['uid']} and u.parentId='' and u.type=0) ";
				}elseif($this->user['type']==3){
				$whereStr.=" and u.gudongId={$this->user['uid']} and u.type=2 or (u.gudongId={$this->user['uid']} and u.zparentId='' and u.parentId='' and u.type!=3) ";
				}
				break;
			case 3:
				// 所有下级
				$whereStr .= "  and (u.parentId={$this->user['uid']} or u.zparentId={$this->user['uid']} or u.gudongId={$this->user['uid']} or u.uid={$this->user['uid']} ) and u.uid !={$this->user['uid']} ";
				break;
			default:
				// 所有人
				$whereStr .= "  and (u.parentId={$this->user['uid']} or u.zparentId={$this->user['uid']} or u.gudongId={$this->user['uid']} or u.uid={$this->user['uid']}) ";
			break;
		}

//状态类型限制
if($para['type'] !=''){
	if($para['type']==99){
		$typeWhere="and c.state=0";
	}else{
		$typeWhere="and c.state={$para['type']}";
	}
}

// 时间限制
if($para['fromTime'] && $para['toTime']){
	$fromTime=strtotime($para['fromTime']);
	$toTime=strtotime($para['toTime'])+24*3600;
	$timeWhere="and c.actionTime between $fromTime and $toTime";
}elseif($para['fromTime']){
	$fromTime=strtotime($para['fromTime']);
	$timeWhere="and c.actionTime>=$fromTime";
}elseif($para['toTime']){
	$toTime=strtotime($para['toTime'])+24*3600;
	$timeWhere="and c.actionTime<$fromTime";
}else{
	$timeWhere=' and c.actionTime>'.strtotime('00:00');
}

$sql="select c.*, u.username, u.parentId from {$this->prename}member_recharge c, {$this->prename}members u where c.uid=u.uid and c.isDelete=0 $rechargeIdWhere $timeWhere $userWhere  $typeWhere $whereStr order by c.id desc";

$data=$this->getPage($sql, $this->page, $this->pageSize);
$sql="select b.home, b.name, u.id, u.account, u.username from {$this->prename}sysadmin_bank u, {$this->prename}bank_list b where b.isDelete=0 and u.admin=1 and u.bankId=b.id";
$bank=$this->getObject($sql, 'id');

	$params=http_build_query($para, '', '&');
?>
<div>
<table width="100%" class='table_b'>
	<thead>
		<tr class="table_b_th">
			<td>充值编号</td>
            <td>用户</td>
			<td>充值金额</td>
			<td>实际到账</td>
			<td>充值前资金</td>
			<td>充值银行</td>
			<td>状态</td>
			<td>备注</td>
			<td>充值时间</td>
		</tr>
	</thead>
	<tbody class="table_b_tr">
	<?php if($data['data']){
	foreach($data['data'] as $var){ ?>
		<tr>
			<td><?=$var['rechargeId']?></td>
			<td><?=$var['username']?></td>
			<td><?=$var['amount']?></td>
			<td><?=$var['rechargeAmount']?></td>
			<td><?=$this->iff($var['state'], $var['coin'], '--')?></td>


			<td><a href="<?=$bank[$var['mBankId']]['home']?>" title="银行帐号：<?=$bank[$var['mBankId']]['account']?>，开户名：<?=$bank[$var['mBankId']]['username']?>" target="_blank"><?=$bank[$var['mBankId']]['name']?></a></td>
			<td><?php
				if($var['state']==1 || $var['state']==2 || $var['state']==9){
					echo '充值成功';
				}elseif($var['state']==3){
					echo '充值失败';
				}elseif($var['state']==0){
					echo '正在充值';
				}?></td>
			<td><?=$var['info']?><?php if($var['depositinfo']){echo '<br>'.$var['depositinfo'];}?></td>
			<td><?=date('Y-m-d H:i:s', $var['actionTime'])?></td>

		</tr>
	<?php } }else{ ?>
    <tr><td colspan="12">暂无充值信息</td></tr>
    <?php } ?>
	</tbody>
</table>
<?php
	$this->display('inc_page.php',0,$data['total'],$this->pageSize, "/index.php/{$this->controller}/{$this->action}-{page}/?$params");
?>
</div>